package team.seekers.hula.question.question.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import team.seekers.hula.common.annotation.ApiResponseBody;
import team.seekers.hula.common.entity.PageResult;
import team.seekers.hula.common.entity.VisibilityUpdateDTO;
import team.seekers.hula.question.question.entity.dto.QuestionQueryDTO;
import team.seekers.hula.question.question.entity.dto.QuestionUpdateDTO;
import team.seekers.hula.question.question.entity.vo.QuestionManageListVO;
import team.seekers.hula.question.question.service.QuestionManageService;
import team.seekers.hula.auth.service.MindUtils;

import java.util.List;

/**
 * @author hbc
 * 管理员对于Question的操作权限有增删改查，其中增删改和前端页面重合，这里只写管理页面的查询方法
 */
@Controller
@ApiResponseBody
@RequestMapping("/manage/question")
public class QuestionManageController {

   @Autowired
   private QuestionManageService questionManageService;


   @DeleteMapping("/delete")
   public void delete(@RequestParam String id) {
      questionManageService.delete(id);
   }

   @PostMapping("/update/info")
   public void update(@RequestBody QuestionUpdateDTO updateDTO){
      questionManageService.updateInfo(updateDTO);
   }

   @PostMapping("/update/visibility")
   public void updateVisibility(@RequestBody VisibilityUpdateDTO updateDTO) {
      questionManageService.updateVisibility(updateDTO);
   }


   @GetMapping("/pageOrderByTime")
   public PageResult<QuestionManageListVO> page(QuestionQueryDTO questionQuery){
      return questionManageService.page(questionQuery);
   }


   @GetMapping("/list/manage")
   public List<QuestionManageListVO> listManageQuestion(){
      return questionManageService.listManageQuestion(MindUtils.getUserId());
   }

}
